<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
    />
    <meta name="author" content="林镭特" />
    <title></title>
    <!-- <link href="../bootstrap/css/bootstrap.css" rel="stylesheet"> -->
    <style>
      .box {
        width: 100px;
        border: 1px solid #000;
        padding: 10px;
      }

      #select-reverse {
        color: blue;
        cursor: pointer;
      }
      .box-header {
        margin-bottom: 10px;
        padding-bottom: 5px;
        border-bottom: 1px solid #000;
      }
      .box-options input {
        width: 20%;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="box-header">
        <input type="checkbox" name="all" id="all" />全选
        <span id="select-reverse">反选</span>
      </div>
      <div class="box-options">
        <input type="checkbox" />选项1 <input type="checkbox" />选项2
        <input type="checkbox" />选项3 <input type="checkbox" />选项4
        <input type="checkbox" />选项5 <input type="checkbox" />选项6
        <input type="checkbox" />选项7 <input type="checkbox" />选项8
        <input type="checkbox" />选项9 <input type="checkbox" />选项10
      </div>
    </div>
    <script>
      var chooseall = document.querySelector(".box-header input");
      var choose = document.querySelectorAll(".box-options input");
      var reverse = document.querySelector("span");

      chooseall.onclick = function() {
        // for(var i = 0; i < choose.length; i++){
        //   choose[i].checked=this.checked;
        // }
        // ischooseall();
        chooall()
      };






      function chooall() {
        console.log(chooseall.checked);
        if (chooseall.checked == true) {
          for (var i = 0; i < choose.length; i++) {
            choose[i].checked = true;
          }
        } else {
          for (var i = 0; i < choose.length; i++) {
            choose[i].checked = false;
          }
        }
      }

      reverse.onclick = function() {
        reversechoose();
      };

      function reversechoose() {
        for (var i = 0; i < choose.length; i++) {
          if (choose[i].checked == true) {
            choose[i].checked = false;
          } else {
            choose[i].checked = true;
          }
        }
      }

      // for(var i = 0; i < choose.length; i++){
      //   choose[i].onclick=function(){
      //     chooall()
      //   }
      // }

    </script>
    <!-- <script src="../bootstrap/js/jquery.js"></script>
  <script src="../bootstrap/js/bootstrap.js"></script> -->
  </body>
</html>
